<template>
	<view>
		<view class="bg-white">
			<view class="space-between  padding">
				<view class="cu-avatar bg-white sm lefticon">
					<view class="cuIcon-location cuIcon default" :class="'text-'+theme"></view>
				</view>
				<view class="w100 padding-lr" v-if="address">
					<view class="text-black text-lg">
						<text class="">{{address.realname}}</text>
						<text class="margin-left">{{address.mobile}}</text>
					</view>
					<view class="text-gray" style="margin-top: 10rpx;">{{address.address_name}}-{{address.address_details}}</view>
				</view>
				<view v-else class="w100 padding-lr text-gray">
					<text v-if="edit">暂无地址，请点击右侧按钮添加</text>
					<text v-else>加载中...</text>
				</view>
				<view class="solid-left padding-left" v-if="edit">
					<view class="cuIcon-edit cuIcon default" :class="'text-'+theme" @tap="editAddress"></view>
				</view>
			</view>
			<view class="bottomline"></view>
		</view>
	</view>
</template>

<script>
	export default {
		props: {
			edit: {
				type: Boolean,
				default: true
			}
		},
		created: function(e) {
			// let address_default = this.$common.getCache('address_default')
			// if(!address_default){
			// 	this.getDefaultAddress()
			// } else this.address = address_default
		},
		data() {
			return {
				address: null,
				CLOUDPATH: this.$config.cloudPath,
				theme: this.$config.THEME(),
			}
		},
		methods: {
			getDefaultAddress() {
				this.$http
					.get('get_default_address', {})
					.then((response) => {
						this.address = response.data.data
						this.$common.setCache('address_default', response.data.data)
					})
					.catch((response) => {
						console.log(response)
					})
			},
			getAddress() {
				return this.address
			},
			setAddress(address) {
				this.address = address
				console.log(address)
			},
			editAddress() {
				let address_id = this.address ? this.address.id : 0
				uni.navigateTo({
					url: "/pages/member/address/select?address_id=" + address_id
				})
			}
		},
	}
</script>

<style>
	.lefticon {
		min-width: 30rpx;
	}

	.orange-line {
		width: 100%;
		height: 6rpx;
	}

	.bottomline {
		width: 100%;
		height: 4rpx;
		background-position: 0% 0%;
		background-size: 100% 100%;
		background-repeat: no-repeat;
		background-image: url();
	}
</style>
